var api = require("../../api/api.js");
var utils = require("../../utils/utils.js");
var event = require("../../event/event.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    store_status: 2,
    mPageNum: 1,
    orderHave: true,
    dataList: [],
    check_count: '',
    user_count: ''

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    this.getList();
    event.on('check_store', this, function (data) {
      that.setData({
        store_status: data.store_status,
        mPageNum:1,
        dataList: [],
        orderHave: true
      })
      that.getList();
      
    });
  },
  seleTab: function (e) {
    this.setData({
      store_status: e.currentTarget.id,
      orderHave: false,
      dataList: []
    })
    this.getList()
  },

  //获取列表
  getList: function () {
    var that = this;
    wx.showLoading()
    api.default.api('get_store_list', {
      "store_status": this.data.store_status.toString(),
      "page": this.data.mPageNum
    }, function (data) {
      wx.hideLoading()
      wx.stopPullDownRefresh() //停止下拉刷新
      that.setData({
        orderHave: true
      });
      if (data.data.result.length == 0) { //没有数据且是第一页
        if (that.data.mPageNum <= 1) {
          that.setData({
            orderHave: false
          })
        }else{
          that.data.mPageNum -= 1;
        }
      }
      that.setData({
        dataList: that.data.dataList.concat(data.data.result),
        check_count: data.data.check_count,
        user_count: data.data.user_count
      });
      wx.hideNavigationBarLoading()

    }, function () {
      wx.stopPullDownRefresh() //停止下拉刷新
      wx.hideNavigationBarLoading()
      wx.hideLoading()
    });

  },
  toVerifyClient: utils.throttle(function (e) {
    var index = e.currentTarget.dataset.index;
    var uid = this.data.dataList[index].user_id;
    wx.navigateTo({
      url: '../verifyClient/verifyClient?uid=' + uid,
    })
  }),
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.setData({
      isHidden: false
    });
    this.data.mPageNum += 1;
    this.getList()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})